//
//  albumViewCell.m
//  jingdongfang
//
//  Created by MTiMac02 on 2017/8/28.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "AlbumViewCell.h"
#import "AddPhotoViewController.h"
#import "RenameViewController.h"
#import "MyAltasViewController.h"

@interface AlbumViewCell()<UIActionSheetDelegate, UINavigationControllerDelegate>

@end

@implementation AlbumViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
   
}

- (IBAction)pushBtnClick:(id)sender {
//    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"添加图片", @"重命名", @"删除",nil];
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:NSLocalizedString(@"Cancel", nil) destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"Add Pictures", nil), NSLocalizedString(@"Rename", nil), NSLocalizedString(@"Delete", nil),nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleDefault;//默认风格，灰色背景，白色文字
    [actionSheet showInView:self];
}

-(void)setAtlasListmodel:(IGAtlasListModel *)atlasListmodel
{
    if (_atlasListmodel != atlasListmodel)
    {
        _atlasListmodel = atlasListmodel;
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    NSString  *klanguage = [[NSUserDefaults standardUserDefaults] objectForKey:KLanguage];
    [_albumIcon sd_setImageWithURL:[NSURL URLWithString:self.atlasListmodel.image] placeholderImage:[UIImage imageNamed:@"atlas-defaul"]];
    _albumName.text=self.atlasListmodel.title;
//    _numberLabel.text=[NSString stringWithFormat:@"共%@张图", self.atlasListmodel.aNum];
    _numberLabel.text=[NSString stringWithFormat:@"%@ %@", self.atlasListmodel.aNum,NSLocalizedString(@"Pictures", nil)];
//    if ([self.atlasListmodel.aNum integerValue]==0||[self.atlasListmodel.aNum integerValue]==1) {
//        if ([klanguage containsString:@"en" ]) {
//            _numberLabel.text=[NSString stringWithFormat:@"%@ %@", self.atlasListmodel.aNum,NSLocalizedString(@"Picture", nil)];
//        }else{
//            _numberLabel.text=[NSString stringWithFormat:@"%@ %@", self.atlasListmodel.aNum,NSLocalizedString(@"Pictures", nil)];
//        }
//
//    }

//    _isExsitLabel.text = @"已在该图册";
    _isExsitLabel.text = NSLocalizedString(@"Added already", nil);
    
    _pushBtn.hidden = _worksId.length > 0 ? YES : NO;
    _isExsitLabel.hidden = (_worksId.length > 0 && [_atlasListmodel.ifExist isEqualToString:@"1"]) ? NO : YES;
    _albumName.textColor = (_worksId.length > 0 && [_atlasListmodel.ifExist isEqualToString:@"1"]) ? [UIColor c5Color] : [UIColor c4Color];
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark - UIActionSheetDelegate
//根据被点击的按钮做出反应，0对应destructiveButton，之后的button依次排序
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSLog(@"添加图片");
        AddPhotoViewController *addVC=[[AddPhotoViewController alloc]init];
        addVC.albumId=self.atlasListmodel.aID;
        [UIViewController ig_pushViewController:addVC animated:YES];
//        [UIViewController ig_pushViewControllerClass:[AddPhotoViewController class] animated:YES];
    }
    else if (buttonIndex == 1) {
        NSLog(@"重命名");
        RenameViewController *vc=[[RenameViewController alloc]init];
        vc.albumId=self.atlasListmodel.aID;
        vc.name=self.atlasListmodel.title;
        [UIViewController ig_pushViewController:vc animated:YES];
    }
    else if (buttonIndex==2){
        NSLog(@"删除");
        self.deleteCell();
        [UIViewController ig_popViewController:[MyAltasViewController class]];
    }
}

@end
